home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / include / MotifApp / Cmd.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-17  |  2.7 KB  |  88 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////////////////////////////////////////////////////////
  3. //         This example code is from the book:
  4. //
  5. //           Object-Oriented Programming with C++ and OSF/Motif
  6. //         by
  7. //           Douglas Young
  8. //           Prentice Hall, 1992
  9. //           ISBN 0-13-630252-1    
  10. //
  11. //         Copyright 1991 by Prentice Hall
  12. //         All Rights Reserved
  13. //
  14. //  Permission to use, copy, modify, and distribute this software for 
  15. //  any purpose except publication and without fee is hereby granted, provided 
  16. //  that the above copyright notice appear in all copies of the software.
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //////////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. /////////////////////////////////////////////////////////
  22. // Cmd.h: A base class for all command objects
  23. /////////////////////////////////////////////////////////
  24. #ifndef CMD_H
  25. #define CMD_H
  26.  
  27. class CmdList;
  28. class CmdInterface;
  29.  
  30. class Cmd {
  31.     
  32.     friend CmdInterface;
  33.     
  34.   private:
  35.     
  36.     // Lists of other commands to be activated or deactivated
  37.     // when this command is executed or "undone"
  38.     
  39.     CmdList       *_activationList;
  40.     CmdList       *_deactivationList;
  41.     void            revert();   // Reverts object to previous state
  42.     int            _active;     // Is this command currently active?
  43.     int            _previouslyActive; // Previous value of _active
  44.     char          *_name;             // Name of this Cmd
  45.     CmdInterface **_ci;            
  46.     int            _numInterfaces;
  47.     
  48.   protected:
  49.     
  50.     int           _hasUndo;    // True if this object supports undo
  51.     static Cmd   *_lastCmd;    // Pointer to last Cmd executed
  52.     
  53.     virtual void doit()   = 0;  // Specific actions must be defined
  54.     virtual void undoit() = 0;  // by derived classes
  55.     
  56.  
  57.   public:
  58.     
  59.     Cmd ( char *,  int ); // Protected constructor
  60.     
  61.     virtual ~Cmd ();                 // Destructor
  62.     
  63.     // public interface for executing and undoing commands
  64.     
  65.     virtual void execute();  
  66.     void    undo();
  67.     
  68.     void    activate();   // Activate this object
  69.     void    deactivate(); // Deactivate this object
  70.     
  71.     // Functions to register dependent commands
  72.     
  73.     void    addToActivationList ( Cmd * );
  74.     void    addToDeactivationList ( Cmd * );
  75.     
  76.     // Register an UIComponent used to execute this command
  77.     
  78.     void    registerInterface ( CmdInterface * );
  79.     
  80.     // Access functions 
  81.     
  82.     int active () { return _active; }
  83.     int hasUndo() { return _hasUndo; }
  84.     const char *const name () { return _name; }
  85.     virtual const char *const className () { return "Cmd"; }
  86. };
  87. #endif
  88.